﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Sgml.Validation;
using Engine.Sgml.Merging;
using Engine.Sgml.Validation.Rules;

namespace Engine.Sgml.Allocation {
    internal sealed class SurroundBlockAllocator : IBlockAllocator {

        public void Allocate(BlockItem item, AllocationContext context) {
            SElement ancestor = item.Ancestor;
            IList<InconsistentBlock> blocks = item.InconsistentBlocks;
            for (int j = 0; j < blocks.Count; j++) {
                InconsistentBlock block = blocks[j];
                if (context.Rules[ancestor].CanSurround(block, ancestor)) {
                    // TODO: if surrounding successfully completed
                    // trace information about this
                    context.Rules[ancestor].Surround(block, ancestor);
                    blocks.RemoveAt(j--);
                    }
                }
            }
        }
    }
